﻿using FluentValidation;
using FluentValidation.Results;
using System.Collections.Generic;
using System.Text;

namespace DTM.Core.Exceptions
{
    /// <summary>
    /// Class <see cref="CustomValidationException"/> define custom validation exception
    /// </summary>
    public class CustomValidationException : ValidationException
    {
        #region Properties

        /// <summary>
        /// Gets a message that describes the current exception.
        /// </summary>
        /// <returns>The error message that explains the reason for the exception, or an empty string("").</returns>
        public override string Message
        {
            get
            {
                if (Errors != null)
                {
                    var result = new StringBuilder();
                    foreach (ValidationFailure error in Errors)
                    {
                        result.AppendLine(error.ErrorMessage);
                    }
                    return result.ToString();
                }
                return base.Message;
            }
        }

        #endregion Properties

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomValidationException"/> class.
        /// </summary>
        /// <param name="errors">The list.</param>
        public CustomValidationException(IList<ValidationFailure> errors)
            : base(errors)
        {
        }

        #endregion Constructors
    }
}